<?php require_once('../Connections/con_gl.php'); ?>
<?php
$act = $_GET[act];
$url = "index.php?component=customerretail";

/* Validasi */
if (trim($_POST['nama']) == '') {
	$error[] = '- Nama harus diisi !!!';
}
if (trim($_POST['alamat']) == '') {
	$error[] = '- Alamat harus diisi !!!';
}
if (trim($_POST['tlp']) == '') {
	$error[] = '- No Telpon harus diisi !!!';
}
if (trim($_POST['email']) <> '' AND !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST[email])){ 
	$error[] = '- Format Email abcde@xxxx.com  !!!';
}

/*End validasi */
if (isset($error)) {
	echo "<b>Error</b>: <br />".implode("<br />", $error);
}else{
	if($act =='add') {
	$query = "INSERT INTO gl_kontak (id, type, tcustomer, tretail, nama, jeniskelamin, tempatlahir, tgllahir, tgldaftar, area, gudang, cabang, npwp, ktp, masaberlakuktp, alamat, tlp, fax, email, status, keterangan, nama1, alamat1, tlp1) VALUES (NULL, 'Customer', 'Retail' , '$_POST[tretail]', '$_POST[nama]', '$_POST[jeiskelamin]', '$_POST[tempatlahir]', '$_POST[tgllahir]', '$_POST[tgldaftar]', '$_POST[area]','$_POST[cabang]', '$_POST[cabang]', '$_POST[npwp]','$_POST[ktp]', '$_POST[masaberlakuktp]','$_POST[alamat]', '$_POST[tlp]', '$_POST[fax]','$_POST[email]', '$_POST[statuscustomer]', '$_POST[keterangan]', '$_POST[nama1]', '$_POST[alamat1]','$_POST[tlp1]')";
	}else if($act=='edit'){
	$query ="UPDATE gl_kontak SET tcustomer='Retail', tretail='$_POST[tretail]', nama='$_POST[nama]', jeniskelamin='$_POST[jeniskelamin]', tempatlahir='$_POST[tempatlahir]', tgllahir='$_POST[tgllahir]', tgldaftar='$_POST[tgldaftar]', area='$_POST[area]', cabang='$_POST[cabang]', gudang='$_POST[cabang]', npwp='$_POST[npwp]', ktp='$_POST[ktp]', masaberlakuktp='$_POST[masaberlakuktp]',alamat='$_POST[alamat]', tlp='$_POST[tlp]', fax='$_POST[fax]',email='$_POST[email]', status='$_POST[statuscustomer]', keterangan='$_POST[keterangan]', nama1='$_POST[nama1]', alamat1='$_POST[alamat1]',tlp1='$_POST[tlp1]'  WHERE id='$_POST[id]'";
	}else{
	$query = "delete from gl_kontak where id='$_POST[id]'";
	}
	mysql_select_db($database_con_gl, $con_gl);
	$runquery = mysql_query($query, $con_gl);
	if($runquery) {
		echo "<img src=\"images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Data berhasil ";if($act=='add' OR $act=='edit') { echo "disimpan";}else{ echo "dihapus"; } echo " ...";
	}else{
		echo "<img src=\"images/alert.png\" align=\"left\" width=\"16\"> Data gagal disimpan !!!";
	}
}
?>
<?php if($runquery) { ?><script type="text/javascript">setTimeout("location.href='<?php echo $url;?>'", 2000);</script><?php } ?>